import com.alibaba.fastjson.JSON;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class HttpClientTest {

    public static void main(String[] args) throws IOException {

        CloseableHttpClient client = HttpClientBuilder.create().build();

        HttpGet httpGet=new HttpGet("http://wthrcdn.etouch.cn/weather_mini?city=石家庄");

        CloseableHttpResponse httpResponse = null;

        httpResponse=client.execute(httpGet);
        int x =httpResponse.getStatusLine().getStatusCode();
        if(x==200){
        String jsonstr= EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
            System.out.println(jsonstr);

            TianqiResult tianqiResult=JSON.parseObject(jsonstr,TianqiResult.class);
            System.out.println(tianqiResult.getData().getWendu());
            System.out.println(tianqiResult.getData().getForecast().get(0).getDate());
            String low =tianqiResult.getData().getForecast().get(0).getLow();

            Map map = new HashMap<>();
            map.put("low",tianqiResult.getData().getForecast().get(0).getLow());
            map.put("high",tianqiResult.getData().getForecast().get(0).getHigh());
            map.put("type",tianqiResult.getData().getForecast().get(0).getType());
            System.out.println(JSON.toJSONString(map));
            System.out.println(low.substring(3));
        }else {
            System.out.println("ERROR CODE:"+x);
        }


    }


}
